import Service from '../../core/baseService';

export default class SysSiteService extends Service {
  constructor(ctx) {
    super(ctx);
    this.model = ctx.model.SysConfigAttr;
  }

  async attrList(page = 1, pageSize = 20, query = {}) {
    const result: any = await this.model
      .findAndCountAll({
        where: query,
        offset: (Number(page) - 1) * pageSize,
        limit: pageSize,
        order: [['order', 'ASC']],
      });
    return {
      list: result.rows,
      total: result.count,
      page,
      pageSize,
    }
  };

  async update(params) {
    const fetch = (defaultValue, name) => this.model
      .update(
        {
          defaultValue
        },
        {
          where: {
            'field': name
          }
        }
      );

    const allFetch = Object.keys(params).map((it: any) => fetch(params[it], it));
    const result = await Promise.all(allFetch);
    return result;
  }


}
